<?php include _include(ADMIN_PATH.'view/htm/header.inc.htm');?>

<div class="row">
	<div class="col-lg-10 mx-auto">
	
		<div class="btn-group mb-3" role="group">
			<?php echo admin_tab_active(array(
					'set'=>array('url'=>url('plugin-setting-xn_search-set'), 'text'=>lang('admin_setting_search_set')),
					'cutword'=>array('url'=>url('plugin-setting-xn_search-cutword'), 'text'=>lang('admin_setting_search_cutword'))
				), $action);?>
		</div>
		
		<div class="card">
			<div class="card-body">
				<form action="" method="get" id="form">
					<div class="form-group row" id="fulltext">
						<label class="col-sm-2 form-control-label">中文切词 API：</label>
						<div class="col-sm-10">
							<?php echo $search_conf['cutword_url']; ?>
						</div>
					</div>
					<div class="form-group row">
						<label class="col-sm-2 form-control-label">当前主题贴数：</label>
						<div class="col-sm-10">
							<?php echo $runtime['threads']; ?>
						</div>
					</div>
					<div class="form-group row">
						<label class="col-sm-2 form-control-label">总贴数：</label>
						<div class="col-sm-10">
							<?php echo $posts; ?>
						</div>
					</div>
					<div class="form-group row">
						<label class="col-sm-2 form-control-label">切词范围：</label>
						<div class="col-sm-10">
							<?php echo $input['range']; ?>
						</div>
					</div>
					<div class="form-group row hide" id="all_start_div">
						<label class="col-sm-2 form-control-label">进度：</label>
						<div class="col-sm-10">
							<?php echo $input['all_start']; ?>
						</div>
					</div>
					<div class="form-group row hide" id="post_start_div">
						<label class="col-sm-2 form-control-label">进度：</label>
						<div class="col-sm-10">
							<?php echo $input['post_start']; ?>
						</div>
					</div>
					<div class="form-group row">
						<label class="col-sm-2 form-control-label"></label>
						<div class="col-sm-10">
							<button type="submit" class="btn btn-primary btn-block" id="submit" data-loading-text="<?php echo lang('submiting');?>..."><?php echo lang('admin_start_cut_word');?></button>
							<a role="button" class="btn btn-secondary btn-block mt-3" href="javascript:history.back();"><?php echo lang('back');?></a>
						</div>
					</div>
					
				</form>
			</div>
		</div>
	</div>
</div>

<?php include _include(ADMIN_PATH.'view/htm/footer.inc.htm');?>

<script>

var jform = $("#form");
var jsubmit = $("#submit");
var jrange = jform.find('input[name="range"]');
var jall_start_div = $('#all_start_div');
var jpost_start_div = $('#post_start_div');
var jall_start = jform.find('input[name="all_start"]');
var jpost_start = jform.find('input[name="post_start"]');
jform.on('submit', function()
{
	
	jform.reset();
	jsubmit.button('loading');
	var range = jrange.checked();
	var start = (range == 0 ? jall_start.val() : jpost_start.val());
	window.location = xn.url('plugin-setting-xn_search-cutstep-'+range+'-'+start);
	return false;
});

function on_range_change(v) {
	if(v == 0) {
		jall_start_div.show();
		jpost_start_div.hide();
	} else {
		jall_start_div.hide();
		jpost_start_div.show();
	}
}
jrange.on('change', function() {on_range_change($(this).val());});
on_range_change(jrange.checked());
</script>